package com.cj.cms.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cj.cms.dao.security.LeaveWordDao;
import com.cj.cms.entity.LeaveWord;
import com.cj.common.orm.hibernate.EntityManager;
import com.cj.sys.service.ServiceException;

@Service
@Transactional
public class LeaveWordManager extends EntityManager<LeaveWord, Long>{
	@Autowired
	private LeaveWordDao leaveWordDao;
	
	public void publish(Long id){
		publish(super.load(id));
	}
	public void publish(LeaveWord leaveWord){
		try {
			if(leaveWord == null || leaveWord.getId() == null)
				return;
			if(leaveWord.getIsOpen() == 0)
				leaveWord.setIsOpen(1);
			else
				leaveWord.setIsOpen(0);
			leaveWordDao.save(leaveWord);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new ServiceException("publish Error!" + e.getMessage(), e);
		}
	}
	@Override
	protected LeaveWordDao getEntityDao() {
		return leaveWordDao;
	}	
}
